package me.zhengjie.sqlservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import me.zhengjie.mapper.WcsLineBodyPalletMapper;
import me.zhengjie.pojo.entity.WcsLineBodyPallet;
import me.zhengjie.sqlservice.WcsLineBodyPalletService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class WcsLineBodyPalletServiceImpl extends ServiceImpl<WcsLineBodyPalletMapper, WcsLineBodyPallet> implements WcsLineBodyPalletService {
    private final WcsLineBodyPalletMapper wcsLineBodyPalletMapper;
    @Override
    public WcsLineBodyPallet selectWorkOrder(String workOrder) {
        LambdaQueryWrapper<WcsLineBodyPallet> wcsLineBodyPalletLambdaQueryWrapper = new LambdaQueryWrapper<>();
        wcsLineBodyPalletLambdaQueryWrapper.eq(WcsLineBodyPallet::getWorkOrder,workOrder);
        return wcsLineBodyPalletMapper.selectOne(wcsLineBodyPalletLambdaQueryWrapper);
    }

    @Override
    public boolean updatePalletQuantity(Integer palletId, Integer palletQuantity) {
        LambdaUpdateWrapper<WcsLineBodyPallet> wcsLineBodyPalletLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        wcsLineBodyPalletLambdaUpdateWrapper.set(WcsLineBodyPallet::getPalletQuantity,palletQuantity)
                .eq(WcsLineBodyPallet::getPalletId,palletId);
        return wcsLineBodyPalletMapper.update(null,wcsLineBodyPalletLambdaUpdateWrapper)>0;
    }

    @Override
    public Integer selectCount() {
        return Math.toIntExact(wcsLineBodyPalletMapper.selectCount(null));
    }

    @Override
    public List<WcsLineBodyPallet> selectList() {
        return wcsLineBodyPalletMapper.selectList(null);
    }

    @Override
    public boolean insert(WcsLineBodyPallet wcsLineBodyPallet) {
        return wcsLineBodyPalletMapper.insert(wcsLineBodyPallet)>0;
    }

    @Override
    public WcsLineBodyPallet selectPalletId(Integer palletId) {
        LambdaQueryWrapper<WcsLineBodyPallet> wcsLineBodyPalletLambdaQueryWrapper = new LambdaQueryWrapper<>();
        wcsLineBodyPalletLambdaQueryWrapper.eq(WcsLineBodyPallet::getPalletId,palletId);
        return wcsLineBodyPalletMapper.selectOne(wcsLineBodyPalletLambdaQueryWrapper);
    }

    @Override
    public boolean deleteId(Integer palletId) {
        return wcsLineBodyPalletMapper.deleteById(palletId) >0;
    }
}
